import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';
import { string } from 'vue-types';

enum Api {
  page = '/template/page',
  listVelocityVar = '/template/listVelocityVar',
  listByGroupId = '/template/listByGroupId',
  copy = '/template/copy',
  save = '/template/save',
  edit = '/template/update',
  get = '/template/getById',
  delete = '/template/delete',
  deleteBatch = '/template/deleteBatch',
  importExcel = '/template/importExcel',
	exportXls = '/template/exportXls',
}

/**
 * 导出api
 */
export const getExportUrl = Api.exportXls;

export const getImportUrl = Api.importExcel;

/**
 * 查询模板列表
 * @param params
 */
export const pageTemplate = (params) => {
  return defHttp.get({ url: Api.page, params });
};

/**
 * 查询模板列表
 * @param params
 */
 export const listByGroupId = (params) => {
  return defHttp.get({ url: Api.listByGroupId, params});
};

/**
 * 查询模板引擎Velocity变量列表
 * @param params
 */
 export const listVelocityVar = () => {
  return defHttp.get({ url: Api.listVelocityVar });
};


/**
 * 保存或者更新模板
 * @param params
 */
export const saveOrUpdateTemplate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};

/**
 * 拷贝模板
 * @param params
 */
 export const copyTemplate = (params) => {
  return defHttp.post({ url: Api.copy, params });
};


/**
 * 查询模板详情
 * @param params
 */
export const getTemplateById = (params) => {
  return defHttp.get({ url: Api.get, params });
};

/**
 * 删除模板
 * @param params
 */
export const deleteTemplate = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 批量删除模板
 * @param params
 */
export const batchDeleteTemplate = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};
